﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Sharp.Domain.Model;
using Sharp.Domain.PlatformBoundedContext.WorkFlowModule.Engine.Common;
using Sharp.Domain.PlatformBoundedContext.WorkFlowModule.Engine.Xpdl;
using Sharp.Infrastructure;

namespace Sharp.Domain.PlatformBoundedContext.WorkFlowModule.Aggregates
{
    /// <summary>
    /// 活动实例的实体对象
    /// </summary>
    [Table("WorkFlow_ActivityInstances")]
    public class ActivityInstanceEntity : IAggregateRoot<int>, ILogCreatedExEntity,ILogModifiEntity
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Column(Order = 0)]
        public int Id { get; set; }

        [Required]
        [Column(Order = 1)]
        public int ProcessInstanceID { get; set; }

        [Required]
        [Column(Order = 2)]
        [MaxLength(50)]
        public string AppName { get; set; }

        [Required]
        [Column( Order = 3)]
        [MaxLength(50), NonUnicode]
        public string AppInstanceID { get; set; }

        [Required]
        [Column( Order = 4)]
        [MaxLength(100), NonUnicode]
        public string ProcessGUID { get; set; }

        [Required]
        [Column(  Order = 5)]
        [MaxLength(100), NonUnicode]
        public string ActivityGUID { get; set; }

        [Required]
        [Column(Order = 6)]
        [MaxLength(50)]
        public string ActivityName { get; set; }

        [Required]
        [Column(Order = 7)]
        public ActivityTypeEnum ActivityType { get; set; }

        [Required]
        [Column(Order = 8)]
        public ActivityStateEnum ActivityState { get; set; }

        [Required]
        [Column(Order = 9)]
        public WorkItemTypeEnum WorkItemType { get; set; }

        [Column( Order = 10)]
        [MaxLength(1000)]
        public string AssignedToUserIDs { get; set; }

        [Column(  Order = 11)]
        [MaxLength(2000)]
        public string AssignedToUserNames { get; set; }

        [Column(Order = 12)]
        public BackwardTypeEnum BackwardType { get; set; }

        [Column(Order = 13)]
        public int? BackSrcActivityInstanceID { get; set; }

        [Column(Order = 14)]
        public GatewayDirectionEnum GatewayDirectionTypeID { get; set; }

        [Required]
        [Column(Order = 15)]
        public byte CanRenewInstance { get; set; }

        [Required]
        [Column(Order = 16)]
        public int TokensRequired { get; set; }

        [Required]
        [Column(Order = 17)]
        public int TokensHad { get; set; }

        [Column(Order = 18)]
        public ComplexTypeEnum ComplexType { get; set; }

        [Column(Order = 19)]
        public MergeTypeEnum MergeType { get; set; }

        [Column(Order = 20)]
        public Nullable<int> MIHostActivityInstanceID { get; set; }

        [Column(Order = 21)]
        public Nullable<short> CompareType { get; set; }

        [Column(Order = 22)]
        public Nullable<double> CompleteOrder { get; set; }

        [Column(Order = 23)]
        public Nullable<short> SignForwardType { get; set; }

        [Required]
        [Column(  Order = 24)]
        public int? CreatedUserId { get; set; }

        [Required]
        [Column(Order = 25)]
        [MaxLength(50)]
        public string CreatedUserName { get; set; }

        [Required]
        [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
        [Column(Order = 26)]
        public System.DateTime? CreatedTime { get; set; }

        [Column(  Order = 27)]
        public int? ModifiedUserId { get; set; }

        [Column(Order = 28)]
        [MaxLength(50)]
        public string LastUpdatedByUserName { get; set; }

        [Column(Order = 29)]
        public Nullable<System.DateTime> ModifiTime { get; set; }

        [Column(Order = 30)]
        public Nullable<System.DateTime> EndedDateTime { get; set; }

        [Column(  Order = 31)]
        [MaxLength(50), NonUnicode]
        public string EndedByUserID { get; set; }

        [Column(Order = 32)]
        [MaxLength(50)]
        public string EndedByUserName { get; set; }

        [Required]
        [Column(Order = 33)]
        public byte RecordStatusInvalid { get; set; }

        [Timestamp]
        [Column(Order = 34)]
        public byte[] RowVersionID { get; set; }

        public virtual ICollection<TaskEntity> Tasks { get; set; }

        [ForeignKey("ProcessInstanceID")]
        public virtual ProcessInstanceEntity ProcessInstance { get; set; }
        public ICollection<TransitionInstanceEntity> TransitionInstances { get; set; }
    }
}
